<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file="common/head" /}
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form action="" id="form" class="layui-form" method="post">
            <input type="hidden" name="article_id" value="{$info.article_id|default=0}">
            <div class="layui-form-item">
                <label for="cat_id" class="layui-form-label">
                    <span class="x-red">*</span>文章分类
                </label>
                <div class="layui-input-inline">
                    <div class="layui-input-inline">
                        <select id="cat_id" name="cat_id" lay-filter="cat_id">
                            <option value="0">选择分类</option>
                            {foreach $plist as $key=>$vo }
                            <option value="{$vo['cat_id']}">{$vo.cat_name}</option>

                            {notempty name="vo['child']"}
                            {foreach $vo['child'] as $k1=>$two}
                            <option value="{$two['cat_id']}">&nbsp;&nbsp;├{$two.cat_name}</option>

                            {notempty name="two['child']"}
                            {foreach $two['child'] as $k1=>$three}
                            <option value="{$three['cat_id']}">&nbsp;&nbsp;&nbsp;&nbsp;├{$three.cat_name}</option>

                            {notempty name="three['child']"}
                            {foreach $three['child'] as $k1=>$fore}
                            <option value="{$fore['cat_id']}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├{$fore.cat_name}</option>
                            {/foreach}
                            {/notempty}


                            {/foreach}
                            {/notempty}

                            {/foreach}
                            {/notempty}
                            {/foreach}
                        </select>

                        <script>$("#cat_id option[value = '{$info.cat_id}']").attr("selected","selected");</script>
                    </div>
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="title" class="layui-form-label">
                    <span class="x-red">*</span>文章标题
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.title}" id="title" name="title" required="" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="keywords" class="layui-form-label">
                    <span class="x-red"></span>关键字
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.keywords}" id="keywords" name="keywords" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">

                </div>
            </div>

            <div class="layui-form-item">
                <label for="author" class="layui-form-label">
                    <span class="x-red"></span>作者
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.author}" id="author" name="author" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>

            {:getUploadImage($info['thumb'],'thumb')}

            <div class="layui-form-item">
                <label for="publish_time" class="layui-form-label">
                    <span class="x-red"></span>预发布时间
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info['publish_time']?date('Y-m-d',$info['publish_time']):date('Y-m-d',time())}" id="publish_time" name="publish_time" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red"></span>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="link" class="layui-form-label">
                    <span class="x-red"></span>链接地址
                </label>
                <div class="layui-input-inline">
                    <input type="text" value="{$info.link}" id="link" name="link" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">前台跳转到指定的链接地址</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red"></span>状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" {eq name="info['status']" value="1"}checked{/eq} lay-skin="primary" title="显示" checked="">
                    <input type="radio" name="status" value="0" {eq name="info['status']" value="0"}checked{/eq} lay-skin="primary" title="隐藏">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="description" class="layui-form-label">
                    <span class="x-red"></span>文章摘要
                </label>
                <div class="layui-input-inline">
                    <textarea id="description" name="description" placeholder="请输入内容" class="layui-textarea">{$info.description}</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red"></span>文章内容
                </label>
                <div class="layui-input-block">
                    {:getEditor($info['content'],'content')}
                </div>
            </div>


            <div class="layui-form-item">
                <label for="ok" class="layui-form-label">
                </label>
                <button id="ok" class="layui-btn" lay-filter="add" lay-submit="">
                    {empty name="info['article_id']"}
                    增  加
                    {else /}
                    修  改
                    {/empty}

                </button>
            </div>
        </form>
    </div>
</div>

<script>
    layui.use(['form', 'layer','laydate','layedit'],
    function() {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer,
            laydate = layui.laydate;

        //自定义验证规则
        form.verify({
            zm: function(value) {
                if(!new RegExp("^[a-zA-Z0-9_\s·]+$").test(value)){
                    return '只能是字母或数字，字母和下划线开头';
                }

                if(!isNaN(value.substr(0,1))){
                    return '只能是字母或数字，字母和下划线开头';
                }
            }
        });

        laydate.render({
            elem: '#publish_time'
        });

        //监听提交
        form.on('submit(add)',
            function(data) {
                $.ajax({
                    type: "POST",
                    url: "{:url()}",
                    data: data.field,
                    success: function (result) {
                        layer.alert(result.msg, {
                            icon: 6
                        },function() {
                            xadmin.close();
                            xadmin.father_reload();
                        });
                    },
                    error: function(data) {
                        layer.alert(data.msg, {
                            icon: 2
                        },function() {
                            xadmin.close();
                        });
                    }

                });
                return false;
            });


    });


</script>

</body>

</html>
